﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace shuju_jiange
{
    public partial class FrmOrderCountDisplay : Form
    {
        public FrmOrderCountDisplay()
        {
            InitializeComponent();
        }
        private string[] strTimes;
        private uint[] uScore;
        private float[] fVlaue;
        public void LoadValue(string[] strTimes,uint[] uScore,float[] fVlaue)
        {
            if(strTimes.Length != uScore.Length || strTimes.Length != fVlaue.Length)
            {
                MessageBox.Show("调用参数出现系统异常，请联系开发人员", "提示");
                return;
            }
            this.strTimes = strTimes;
            this.uScore = uScore;
            this.fVlaue = fVlaue;
        }
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void btnExport_Click(object sender, EventArgs e)
        {
            string file = "";
            saveFileDialog1.Filter = "csv文件|*.csv";
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                file = saveFileDialog1.FileName;
            }
            else
            {
                return;
            }
            if (File.Exists(file)) File.Delete(file);
            FileStream fsw = new FileStream(file, FileMode.Create);
            StreamWriter sw = new StreamWriter(fsw, Encoding.Default);

            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                sw.Write(row.Cells[0].Value + ",");
                sw.Write(row.Cells[1].Value + ",");
                sw.Write(row.Cells[2].Value + "\r\n");
            }
            sw.Close();
            fsw.Close();
            MessageBox.Show("导出完成！");
        }

        private void FrmOrderCountDisplay_Load(object sender, EventArgs e)
        {
            if (strTimes == null || fVlaue == null || uScore == null || strTimes.Length != uScore.Length || strTimes.Length != fVlaue.Length)
            {
                MessageBox.Show("调用参数出现系统异常，请联系开发人员", "提示");
                return;
            }
            for(int i= 0;i< strTimes.Length; i++)
            {
                dataGridView1.Rows.Add(new object[] { strTimes[i] , uScore[i],  fVlaue[i] });
            }
        }
    }
}
